package com.qs.springboot.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConnectionUtil {

    public static Connection getConnection() throws IOException, TimeoutException {
        //定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置主机地址
        factory.setHost("172.16.109.131");
        //端口
        factory.setPort(5672);
        //设置vhost、用户名、密码
        factory.setVirtualHost("/yzg");
        factory.setUsername("admin");
        factory.setPassword("admin");

        //获取连接对象
        return factory.newConnection();
    }


    public static void main(String[] args) throws IOException, TimeoutException {
        System.out.println("-->>>>connection=" + getConnection());
    }
}
